
package vinterprojekt.controller;

/*
 * InputValidator er ansvarlig for ensartet validering af input i forms. Gui-klasserne bruger den via Facade-klassen
 *
 * @author jacob
 */

import java.util.regex.Pattern;

public class InputValidator
{
    private static String isbnPattern = "^(97(8|9))?\\d{9}(\\d|X)$";
    private static Pattern pattern = Pattern.compile(isbnPattern);

    public InputValidator()
    {

    }

    /*
    public boolean validate(String isbn)
    {
        return ISBNValidator.pattern.matcher(isbn.trim()).matches();
    } */

    public boolean validateISBN(String isbn)
    {
        return (!isbn.isEmpty() && isbn.length() == 10 || isbn.length() <= 17);
    }

    public boolean validateSearch(String author, String title)
    {
        if (!author.isEmpty() || !title.isEmpty()) return true;

        else return false;
    }

    public boolean validateCreate(String title, String yearOfPublication, String edition, String publisher, String ISBN, String ISBNSuffix, String remark, String author, boolean avail)
    {
        if (!title.isEmpty() && !yearOfPublication.isEmpty() && !edition.isEmpty() && !publisher.isEmpty() &&
                !ISBN.isEmpty() && !ISBNSuffix.isEmpty() && !remark.isEmpty() && !author.isEmpty()) return true;

        else return false;
    }
}